package com.example.demo;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author yishuangshuang
 * @ClassName: DistinctDemo
 * @Description: TODO
 * @date 2019/1/23 5:15 PM
 */
public class DistinctDemo {
    public static void main(String[] args) {
        Set<String> mobiles = new HashSet<>();
        mobiles.add("xxx");
        mobiles.add("yyy");
        List<Apple> apples = new ArrayList<>();
        Apple apple1 = new Apple(1, "xxx", new BigDecimal("3.25"), 10);
        Apple apple2 = new Apple(1, "苹果2", new BigDecimal("1.35"), 20);
        Apple apple3 = new Apple(2, "苹果2", new BigDecimal("1.35"), 20);
        apples.add(apple1);
        apples.add(apple2);
        apples.add(apple3);
//        for (Apple apple : apples) {
//            if (mobiles.contains(apple.getName())){
//                apples.remove(apple);
//            }
//        }
//        System.out.println(apples);

        ArrayList<Apple> collect = apples.stream().collect(Collectors.collectingAndThen
                (Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(a -> a.getName()))), ArrayList::new));
        System.out.println(collect);
    }


}
